/*
 * Copyright 2018 Dash Core Group
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * This file was generated by SWIG (http://www.swig.org) and modified.
 * Version 3.0.12
 */

package org.dashj.bls;

import com.google.common.base.Preconditions;

public class PublicKeyVector extends java.util.AbstractList<PublicKey> {
  private transient long cPointer;
  protected transient boolean owner;

  protected PublicKeyVector(long cPtr, boolean cMemoryOwn) {
    Preconditions.checkArgument(cPtr != 0);
    owner = cMemoryOwn;
    cPointer = cPtr;
  }

  protected static long getCPtr(PublicKeyVector obj) {
    return (obj == null) ? 0 : obj.cPointer;
  }

  protected void finalize() {
    delete();
  }

  public synchronized void delete() {
    if (cPointer != 0) {
      if (owner) {
        owner = false;
        JNI.delete_PublicKeyVec(cPointer);
      }
      cPointer = 0;
    }
  }

  public PublicKeyVector(java.util.Collection<PublicKey> e) {
    this.reserve(e.size());
    for(PublicKey value: e) {
      this.push_back(value);
    }
  }

  public PublicKeyVector() {
    this(JNI.new_PublicKeyVec__SWIG_0(), true);
  }

  public PublicKeyVector(PublicKeyVector o) {
    this(JNI.new_PublicKeyVec__SWIG_2(PublicKeyVector.getCPtr(o), o), true);
  }

  public long capacity() {
    return JNI.PublicKeyVec_capacity(cPointer, this);
  }

  public void reserve(long n) {
    JNI.PublicKeyVec_reserve(cPointer, this, n);
  }

  public boolean isEmpty() {
    return JNI.PublicKeyVec_isEmpty(cPointer, this);
  }

  public void clear() {
    JNI.PublicKeyVec_clear(cPointer, this);
  }

  public void push_back(PublicKey x) {
    Preconditions.checkNotNull(x);
    JNI.PublicKeyVec_push_back(cPointer, this, PublicKey.getCPtr(x), x);
  }

  public PublicKey get(int i) {
    return new PublicKey(JNI.PublicKeyVec_get(cPointer, this, i), false);
  }

  public PublicKey set(int i, PublicKey VECTOR_VALUE_IN) {
    Preconditions.checkNotNull(VECTOR_VALUE_IN);
    return new PublicKey(JNI.PublicKeyVec_set(cPointer, this, i, PublicKey.getCPtr(VECTOR_VALUE_IN), VECTOR_VALUE_IN), true);
  }

  public int size() {
    return JNI.PublicKeyVec_size(cPointer, this);
  }

  public void removeRange(int from, int to) {
    JNI.PublicKeyVec_removeRange(cPointer, this, from, to);
  }

}
